package com.xinqi.xinqidev.controller;

import com.xinqi.xinqidev.common.Result;
import com.xinqi.xinqidev.common.ResultUtil;
import com.xinqi.xinqidev.entity.Hello;
import com.xinqi.xinqidev.entity.dto.HelloDto;
import com.xinqi.xinqidev.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xin麒
 * @date 2023/10/20 23:30
 */
@CrossOrigin
@RestController
@RequestMapping("/hello")
public class HelloController {
    //简单的测试类：
    @Autowired
    private HelloService helloService;
    @GetMapping("/testSQL")
    public Result<List<Hello>> testSQL(){
        List<Hello> all = helloService.selectAll();
        return ResultUtil.ok(all);
    }

    //复现最原始的写法-without 策略模式
    @PostMapping("/queryWithOutStrategy")
    public Result<String> queryWithOutStrategy(@RequestBody HelloDto helloDto){
        System.out.println("helloDto is "+helloDto);
        String result = helloService.queryWithOutStrategy(helloDto);
        return ResultUtil.ok(result);
    }




    //下面正式介绍策略模式+工厂模式的结合的业务：
    @PostMapping("/query")
    public Result<String> query(@RequestBody HelloDto helloDto){
        System.out.println("helloDto is "+helloDto);
        String result = helloService.queryByHelloDto(helloDto);
        return ResultUtil.ok(result);
    }



}
